<template>
  <div>
    <el-dialog
      title="部门信息"
      :visible.sync="dialogVisible"
      width="600px"
      destroy-on-close
    >
      <div>
        <el-card class="box-card" style="height: 300px; overflow: auto;">
          <div v-for="(it, indx) in deptList" :key="indx" style="margin-top: 10px;">
            <el-radio v-model="deptId" :label="it.id">{{ it.name }}</el-radio>
          </div>
        </el-card>
        
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="!deptId" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { employeeService, departmentService } from "@/api/hrService";

export default {
  dicts: [],
  components: {},

  data() {
    return {
      resolve: null,
      dialogVisible: false,
      deptList: [],
      deptId: "",
      empId: "",
  

      // 表单参数
      form: {
        id: "",
        firstName: undefined,
        code: undefined,
        snote: undefined,
        dob: undefined,
      },

      // 表单校验
      rules: {
        firstName: [
          { required: true, message: "不能为空", trigger: "blur" },
          {
            min: 2,
            max: 20,
            message: "用户名称长度必须介于 2 和 20 之间",
            trigger: "blur",
          },
        ],
        // code: [{ required: true, message: "不能为空", trigger: "blur" }],
      },
    };
  },
  methods: {
    loadAllDepartment() {
      departmentService.list({size: 100}).then((response) => {
        this.deptList = response.data?.data;
      });
    },
    open(row) {
      this.empId = row.id;
      this.deptId = '';
      this.loadAllDepartment();
      console.log(row);
      this.dialogVisible = true;
  
      return new Promise((resolve) => {
        this.resolve = resolve;
      });
    },
    /** 提交按钮 */
    submitForm: function () {


      employeeService.postDept({ empId: this.empId, deptId: this.deptId }).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.dialogVisible = false;
            // this.getList();
            this.resolve(response.data);
          });
     
    },

    // 取消按钮
    cancel() {
      this.dialogVisible = false;
      // this.reset();
    },
  },
};
</script>

<style lang="scss" scoped></style>
